package aiyh.utils;

import aiyh.utils.zwl.common.ToolUtil;
import com.alibaba.fastjson.JSON;


/**
 * @author EBU7-dev1-ayh
 * @create 2021/8/27 0027 10:21
 * api调用结果类封装
 */


public class ApiResult {
	private final int code;
	private final String msg;
	private final Object data;

	public ApiResult(int code, String msg, Object data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}


	public static String successNoData(){
		return ApiResult.success(null, 200, "请求成功！");
	}

	public static String success(Object data){
		return ApiResult.success(data, 200, "请求成功！");
	}

	public static String success(Object data, String msg){
		return ApiResult.success(data, 200, msg);
	}

	public static String success(Object data, int code, String msg){
		return JSON.toJSONString(new ApiResult(code, msg, data));
	}

	public static String error(){
		return ApiResult.error(0, "服务器异常！");
	}

	public static String error(String msg){
		return ApiResult.error(0, msg);
	}

	public static String error(int code, String msg){
		return JSON.toJSONString(new ApiResult(code, msg, null));
	}

	public int getCode() {
		return code;
	}

	public String getMsg() {
		return msg;
	}

	public Object getData() {
		return data;
	}

}
